package main

import "fmt"

func main() {
	e := newParseError("main.go", 1)
	fmt.Println(e.Error())
}

type MyError struct {
	Filename string
	Line     int
}

//为MyError类定义一个Error方法
func (e *MyError) Error() string {
	return fmt.Sprintf("%s的第%d行报错", e.Filename, e.Line)
}

func newParseError(filename string, line int) *MyError {
	//实例化MyError
	return &MyError{filename, line}
}
